//
//  AddWorkExperienceViewController.m
//  InviteJob
//
//  Created by LangLang on 17/10/30.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "AddWorkExperienceViewController.h"
//#import "UICustomDatePicker.h"

@interface AddWorkExperienceViewController ()<MCDatePickerViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *strJobs;
@property (weak, nonatomic) IBOutlet UITextField *strCompanyName;
@property (weak, nonatomic) IBOutlet UITextField *strInduction;
@property (weak, nonatomic) IBOutlet UITextField *strdeparture;
@property (strong, nonatomic) SZTextView *strJobDescription;
@property (weak, nonatomic) IBOutlet UIView *JobDescriptionView;

@property (weak, nonatomic) IBOutlet UIView *showButton;

@property (nonatomic, strong) UIButton *navRightButton;

@property (nonatomic, assign ,getter=isYearShow) BOOL yearShow;

@end

@implementation AddWorkExperienceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = strColor(@"f6f6f6");
    
    // 描述工作信息
    _strJobDescription = [[SZTextView alloc] init];
    _strJobDescription.placeholder = @"请输入工作描述";
    _strJobDescription.font = [UIFont systemFontOfSize:14];
    [_JobDescriptionView addSubview:_strJobDescription];
    [_strJobDescription mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@12);
        make.right.equalTo(@-12);
        make.top.equalTo(@15);
        make.bottom.equalTo(@-10);
    }];
    
    // right item
    self.navRightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    if (_indexEdit == 1) {
        TitleView(@"工作经验")
        _showButton.hidden = NO;
        [self.navRightButton setImage:[UIImage imageNamed:@"icon_news_delete"] forState:UIControlStateNormal];
        self.navRightButton.imageEdgeInsets = UIEdgeInsetsMake(0,15, 0, -15);
        // 传值
        _strJobs.text = _editJobs;
        _strCompanyName.text = _editCompanyName;
        _strInduction.text = _editInduction;
        _strdeparture.text = _editDeparture;
        _strJobDescription.text = _editJobDescription;
        
    }else{
        TitleView(@"添加工作经验")
        [self.navRightButton setTitle:@"提交" forState:UIControlStateNormal];
        self.navRightButton.titleEdgeInsets = UIEdgeInsetsMake(0,10, 0, -10);
        self.navRightButton.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:self.navRightButton];
    self.navigationItem.rightBarButtonItem = rightItem;
    // 事件绑定
    [self.navRightButton addTarget:self action:@selector(navActions) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)navActions{
    if (_indexEdit == 1) {
        
        _strJobs.text        = @"";
        _strCompanyName.text = @"";
        _strInduction.text   = @"";
        _strdeparture.text   = @"";
        _strJobDescription.text   = @"";
        __weak typeof(self) weakSelf = self;
        if (weakSelf.workExperience) {
            weakSelf.workExperience(_strJobs.text, _strCompanyName.text, _strInduction.text, _strdeparture.text, _strJobDescription.text);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else{
        
        if (_strJobs.text.length==0) {
            SHuiMBhudTextTimeStr(@"请填写你的岗位");
            return;
        }
        if (_strCompanyName.text.length==0) {
            SHuiMBhudTextTimeStr(@"请填写公司名称");
            return;
        }
        if (_strInduction.text.length==0) {
            SHuiMBhudTextTimeStr(@"请选择入职时间");
            return;
        }
        if (_strdeparture.text.length==0) {
            SHuiMBhudTextTimeStr(@"请选择离职时间");
            return;
        }
        
        if (_strJobDescription.text.length==0) {
            SHuiMBhudTextTimeStr(@"请输入工作描述");
            return;
        }
        
        __weak typeof(self) weakSelf = self;
        if (weakSelf.workExperience) {
            weakSelf.workExperience(_strJobs.text, _strCompanyName.text, _strInduction.text, _strdeparture.text, _strJobDescription.text);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    
}

- (IBAction)btnSave:(id)sender {
    
    if (_strJobs.text.length==0) {
        SHuiMBhudTextTimeStr(@"请填写你的岗位");
        return;
    }
    if (_strCompanyName.text.length==0) {
        SHuiMBhudTextTimeStr(@"请填写公司名称");
        return;
    }
    if (_strInduction.text.length==0) {
        SHuiMBhudTextTimeStr(@"请选择入职时间");
        return;
    }
    if (_strdeparture.text.length==0) {
        SHuiMBhudTextTimeStr(@"请选择离职时间");
        return;
    }
    
    if (_strJobDescription.text.length==0) {
        SHuiMBhudTextTimeStr(@"请输入工作描述");
        return;
    }
    
    
    if (_strJobs.text == _editJobs &&
         _strCompanyName.text == _editCompanyName &&
        _strInduction.text == _editInduction &&
        _strdeparture.text == _editDeparture &&
        _strJobDescription.text == _editJobDescription) {
        [self.navigationController popViewControllerAnimated:YES];
        return;
    }
    
    __weak typeof(self) weakSelf = self;
    if (weakSelf.workExperience) {
        weakSelf.workExperience(_strJobs.text, _strCompanyName.text, _strInduction.text, _strdeparture.text, _strJobDescription.text);
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

- (IBAction)btnInduction:(id)sender {
    MCDatePickerView *yearView = [[MCDatePickerView alloc] initWithFrame:CGRectZero type:XMGStyleTypeYearAndMonth];
    self.yearShow = YES;
    yearView.delegate = self;
    [yearView show];
    
}

- (IBAction)btnDeparture:(id)sender {
    MCDatePickerView *monthView = [[MCDatePickerView alloc] initWithFrame:CGRectZero type:XMGStyleTypeYearAndMonth];
    self.yearShow = NO;
    monthView.delegate = self;
    [monthView show];
    
}

-(void)didSelectDateResult:(NSString *)resultDate{
    if (self.isYearShow) {
        self.strInduction.text = resultDate;
    }else{
        self.strdeparture.text = resultDate;
    }
    
}


@end
